package es.ubu.interfaz;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import es.ubu.ceudaaj.exercise.ud02.t04.l03.Agenda;
import es.ubu.ceudaaj.exercise.ud02.t04.l03.AgendaFactory;

@SuppressWarnings("serial")
public class PanelBotonesCargarGuardar extends JPanel {

	private static Agenda agenda = null;

	/**
	 * Create the panel.
	 */
	public PanelBotonesCargarGuardar() {

		JButton buttonCargar = new JButton("Cargar", null);
		buttonCargar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				agenda = AgendaFactory.getInstance().getAgendaJAXB();
				agenda.loadXML();
			}
		});
		setLayout(new GridLayout(0, 3, 0, 0));
		buttonCargar.setVerticalTextPosition(SwingConstants.CENTER);
		buttonCargar.setHorizontalTextPosition(SwingConstants.LEADING);
		add(buttonCargar);

		JButton buttonActualizar = new JButton("Actualizar", null);
//		buttonActualizar.addActionListener(new ButtonActualizarActionListener());
		buttonActualizar.setVerticalTextPosition(SwingConstants.BOTTOM);
		buttonActualizar.setHorizontalTextPosition(SwingConstants.CENTER);
		add(buttonActualizar);

		JButton buttonGuardar = new JButton("Guardar", null);
		buttonGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				PanelBotonesCargarGuardar.agenda = AgendaFactory.getInstance()
						.getAgendaJAXB();
				agenda.saveXML();
			}
		});
		add(buttonGuardar);

	}

	public static Agenda getAgenda() {
		return agenda;
	}

	/*
	private class ButtonActualizarActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			actualizarTabla(agenda);
		}
	}
	*/
}
